//
//  UIGestureRecognizerViewController.swift
//  Example
//
//  Created by T AO on 2022/2/16.
//

import UIKit

class UIGestureRecognizerViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        swipeGesture()
    }

}

// MARK: - UIGestureRecognizer

extension UIGestureRecognizerViewController {
    private func swipeGesture() {
        let swipe = UISwipeGestureRecognizer()
        swipe.direction = .up
        view.addGestureRecognizer(swipe)
        
        // 第一种响应手势的写法
//        swipe.rx.event
//            .subscribe(onNext: { [weak self] event in
//                let point = event.location(in: event.view)
//                self?.showAlert(title: "向上滑动", message: "\(point.x),\(point.y)")
//            })
//            .disposed(by: disposeBag)
        
        swipe.rx.event
            .bind { [weak self] event in
                let point = event.location(in: event.view)
                self?.showAlert(title: "向上滑动", message: "\(point.x),\(point.y)")
            }
            .disposed(by: disposeBag)
    }
    
    private func showAlert(title: String, message: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "确定", style: .cancel, handler: nil))
        present(alert, animated: true, completion: nil)
    }
}
